// FullScreenTranparentShow.cpp : implementation file
//

#include "stdafx.h"
#include "MultiMedia.h"
#include "FullScreenTranparentShow.h"
#include "MultiMediaDlg.h"
#include <string>
#define TRANDOBK_TIMEREVENT 9992

#define BUTTON_WIDTH	70
#define BUTTON_HEIGHT	30



// FullScreenTranparentShow dialog

IMPLEMENT_DYNAMIC(FullScreenTranparentShow, CDHtmlDialog)

BEGIN_DHTML_EVENT_MAP(FullScreenTranparentShow)
	/*DHTML_EVENT_ONCLICK(_T("ButtonPlay"), OnButtonPlay)
	DHTML_EVENT_ONCLICK(_T("ButtonPause"), OnButtonPause)*/
END_DHTML_EVENT_MAP()
FullScreenTranparentShow::FullScreenTranparentShow(CWnd* pParent /*=NULL*/)
	: CDHtmlDialog(FullScreenTranparentShow::IDD, FullScreenTranparentShow::IDH, pParent)
{
	desk = GetDesktopWindow();
	desk ->GetClientRect(&re);
}

FullScreenTranparentShow::~FullScreenTranparentShow()
{
}

void FullScreenTranparentShow::DoDataExchange(CDataExchange* pDX)
{
	CDHtmlDialog::DoDataExchange(pDX);
}

void FullScreenTranparentShow::InitializeFullScreenTransparentControl()
{
	m_bIsDestroy = FALSE;
	m_bPause = FALSE;
	m_bPlaying = FALSE;
	m_bExit = FALSE;
	
}

BOOL FullScreenTranparentShow::OnInitDialog()
{
	CDHtmlDialog::OnInitDialog();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

BEGIN_MESSAGE_MAP(FullScreenTranparentShow, CDHtmlDialog)
	ON_WM_SHOWWINDOW()
	ON_WM_CREATE()
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON_FULL_EXIT_TRANS, OnClickedExit)
	ON_BN_CLICKED(IDC_BUTTON_PAUSE__FULL_TRANS, OnClickedPause)
	ON_BN_CLICKED(IDC_BUTTON_PLAY__FULL_TRANS, OnClickedPlay)
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_PROGRESS_BAR,OnNMReleasedcaptureProgressbar)
	ON_WM_TIMER()
	ON_WM_SIZE()
END_MESSAGE_MAP()


BOOL FullScreenTranparentShow::DestroyWindow()
{
	// TODO: Add your specialized code here and/or call the base class
    m_bIsDestroy = TRUE;
	return CDHtmlDialog::DestroyWindow();
}

void FullScreenTranparentShow::OnShowWindow(BOOL bShow, UINT nStatus)
{
	CDHtmlDialog::OnShowWindow(bShow, nStatus);

	// TODO: Add your message handler code here
	SetTimer(1,1000,NULL);
	GetCursorPos(&previousPoint);
	SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)|WS_EX_LAYERED);
	SetLayeredWindowAttributes(RGB(0, 0, 0), 0, LWA_COLORKEY);
	CWnd* desk= GetDesktopWindow();
	CRect rc;
	desk->GetClientRect(&rc);

	SetWindowPos(&CWnd::wndTop, rc.left, rc.Height() * 0.8, rc.Width(), rc.Height()/5, SWP_NOREPOSITION);

	m_bIsDestroy = FALSE;
}

int FullScreenTranparentShow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDHtmlDialog::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here
   float x,y, gap;

	x = 150;
	y =  re.Height() * 0.2 - 50;
	gap = 30;
	
	m_progressBar.Create(WS_CHILD|WS_VISIBLE|PBS_SMOOTH,CRect(10,y - 8,re.Width()-10,y - 3),this,IDC_PROGRESS_BAR);
	m_progressBar.SetBarColor(RGB(255,0,0));
	m_progressBar.SetRange(0,1000);
	y = y +5;

    x = 5*x + BUTTON_WIDTH + gap;
	m_btnPlay.Create(L"Play", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON ,CRect(x, y,x + BUTTON_WIDTH,y + BUTTON_HEIGHT), this,IDC_BUTTON_PLAY__FULL_TRANS);
	m_btnPlay.EnableWindow(true);
	x = x + BUTTON_WIDTH + gap;

	m_btnPause.Create(L"Pause", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(x, y, x + BUTTON_WIDTH,y + BUTTON_HEIGHT), this,IDC_BUTTON_PAUSE__FULL_TRANS);
	m_btnPause.EnableWindow(true);

    x =  x + BUTTON_WIDTH + gap;
	m_btnExit.Create(L"Exit", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(x, y, x + BUTTON_WIDTH,y + BUTTON_HEIGHT), this,IDC_BUTTON_FULL_EXIT_TRANS);
	m_btnExit.EnableWindow(true);
	return 0;
}

void FullScreenTranparentShow::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: Add your message handler code here and/or call default
   GetCursorPos(&currentPoint);
	
	if(currentPoint.x >= re.left && currentPoint.x <=re.right && currentPoint.y >=re.top && currentPoint.y <=re.bottom)
	{
		if(previousPoint.x == currentPoint.x && previousPoint.y == currentPoint.y )
		{
			EnableControlInFS(false);
		}
		if(previousPoint.x != currentPoint.x || previousPoint.y != currentPoint.y )
		{
			EnableControlInFS(true);
		}
		previousPoint = currentPoint;
	}
	else
	{
		EnableControlInFS(false);
	}

	CDHtmlDialog::OnTimer(nIDEvent);
}
void FullScreenTranparentShow::EnableControlInFS(bool flag)
{
	if(flag)
	{
		m_btnPlay.ShowWindow(true);
		m_btnPause.ShowWindow(true);
		m_btnExit.ShowWindow(true);
		m_progressBar.ShowWindow(true);
	}
	else 
	{
		m_btnPlay.ShowWindow(false);
		m_btnPause.ShowWindow(false);
		m_btnExit.ShowWindow(false);
		m_progressBar.ShowWindow(false);
	}
}


void FullScreenTranparentShow::OnClickedExit()
{
	//MessageBox(L"Stop Button",NULL, MB_OK);
	//SetTimer(THUONG_TIMEREVENT,1000,(TIMERPROC)NULL);
	m_bExit = TRUE;
	m_bPause = FALSE;
	m_bPlaying = FALSE;

	
}
void FullScreenTranparentShow::OnClickedPause()
{
	//MessageBox(L"Stop Button",NULL, MB_OK);
	//SetTimer(THUONG_TIMEREVENT,1000,(TIMERPROC)NULL);
	m_bPause = TRUE;
	m_bPlaying = FALSE;
	m_bExit = FALSE;
	
}
void FullScreenTranparentShow::OnClickedPlay()
{
	//MessageBox(L"Stop Button",NULL, MB_OK);
	//SetTimer(THUONG_TIMEREVENT,1000,(TIMERPROC)NULL);
	m_bPlaying = TRUE;
	m_bExit = FALSE;
	m_bPause = FALSE;
	
}

bool FullScreenTranparentShow::SetText(BSTR caption, bool isBold)
{
	// TODO: Add your specialized code here and/or call the base class
	CRect rc;
	this->GetClientRect(&rc);
	
	char setFontsize[33];
	itoa (rc.Height()/6, setFontsize, 10);

	std::string cap = _bstr_t(caption);

	std::string addFontsize;

	if (isBold)
	{	
		addFontsize.append("<b style = 'font-size:");
	}
	else
	{
		addFontsize.append("<span style = 'font-size:");
		
	}

	addFontsize.append(setFontsize);
	addFontsize.append("pt;'>");

	int pos = cap.find(">");
	if (pos > 0) 	
		cap.insert(pos + 1, addFontsize);

	caption =   A2BSTR(cap.c_str());

	IHTMLElement* pLinkElement = NULL;

	if (GetElement(_T("text"), &pLinkElement) == S_OK && pLinkElement != NULL)
	{
		
		 pLinkElement->put_innerHTML(caption);
		 pLinkElement->Release();
		 return true;
	}

		
	return False;
}
void FullScreenTranparentShow::setProgressPos(LONGLONG cur, LONGLONG m_length)
{
	LONGLONG lTimeLineUnit =0;
	//REFERENCE_TIME rtTime;

	lTimeLineUnit=m_length/1000;
	int nPos = (int)cur/lTimeLineUnit;
	m_progressBar.SetPos(nPos);

}
void FullScreenTranparentShow::OnNMReleasedcaptureProgressbar(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: Add your control notification handler code here
	*pResult = 0;
	//CString strTime = CMultiMediaDlg::ShareInstance()->m_VideoMng.SetPosition(m_progressBar.GetPos());
	//m_stcTimePlaying.SetWindowTextW((LPCTSTR)strTime);
	/*if(m_progressBar.GetPos() == 1000)
	{
	}
	else
	{
	}*/
	MessageBoxW(NULL, L"Hello!", MB_OK | MB_ICONEXCLAMATION);
}
